package com.yupi.generator;

import com.yupi.generator.StaticGenerator;
import com.yupi.generator.DynamicGenerator;
import com.yupi.model.DataModel;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;



public class MainGenerator {

/**
* 生成
*
* @param model 数据模型
* @throws TemplateException
* @throws IOException
*/
public static void doGenerate(DataModel model) throws TemplateException, IOException {
String inputRootPath = ".source/acm-template-pro";
String outputRootPath = "generated";

String inputPath;
String outputPath;


        boolean needGit = model.needGit;
        boolean loop = model.loop;
            String author = model.mainTemplate.author;
            String outputText = model.mainTemplate.outputText;
    // 1.先判断是否为分组
        // 2.分组下是否有condition
            if (needGit) {
                // 3.本组文件循环
            inputPath = new File(inputRootPath, ".gitignore").getAbsolutePath();
            outputPath = new File(outputRootPath, ".gitignore").getAbsolutePath();
            StaticGenerator.copyFilesByHutool(inputPath, outputPath);
                // 3.本组文件循环
            inputPath = new File(inputRootPath, "README.md").getAbsolutePath();
            outputPath = new File(outputRootPath, "README.md").getAbsolutePath();
            StaticGenerator.copyFilesByHutool(inputPath, outputPath);
            }
        // 这里是分组的else，复用单个文件的判断
    // 1.先判断是否为分组
        inputPath = new File(inputRootPath, "src/com/yupi/acm/MainTemplate.java.ftl").getAbsolutePath();
        outputPath = new File(outputRootPath, "src/com/yupi/acm/MainTemplate.java").getAbsolutePath();
        DynamicGenerator.doGenerate(inputPath, outputPath, model);
}
}










